package com.ml.mall.service.shop.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ml.mall.bean.page.Page;
import com.ml.mall.bean.req.shop.ShopSupplierQueryDto;
import com.ml.mall.bean.req.variant.VariantRecommendQueryShopReq;
import com.ml.mall.bean.res.product.SysProductShopPageRes;
import com.ml.mall.bean.vo.coupon.CouponVo;
import com.ml.mall.bean.vo.coupon.UsableCouponVo;
import com.ml.mall.entity.deduct.SysADeduct;
import com.ml.mall.mapper.variant.SysProductVariantRecommendMapper;
import com.ml.mall.service.coupon.SysCouponService;
import com.ml.mall.service.deduct.SysADeductService;
import com.ml.mall.service.shop.ShopRecommendService;
import com.ml.mall.service.shop.ShopService;
import com.ml.mall.service.variant.SysProductVariantService;
import com.ml.mall.utils.OrderPriceUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


/**
 *   @description    :description 
 *   @author         :zxm
 *   @date           :2021/5/26
 *   @version        :1.0
**/
@Slf4j
@Service
public class ShopRecommendServiceImpl implements ShopRecommendService {

    @Autowired
    private SysProductVariantRecommendMapper sysProductVariantRecommendMapper;
    @Autowired
    private ShopService shopService;
    @Autowired
    private SysADeductService sysADeductService;
    @Autowired
    private SysProductVariantService sysProductVariantService;

    @Override
    public Page<SysProductShopPageRes> queryVariantRecommendShop(VariantRecommendQueryShopReq req) {
        Page<SysProductShopPageRes> page = new Page<>(req.getPageIndex(),req.getPageNum());
        List<SysProductShopPageRes> listItem = sysProductVariantRecommendMapper.queryVariantRecommendShop(req);
        //重新根据提成比例设置售价
        SysADeduct curDeduct = sysADeductService.getCurDeduct();
        listItem.stream().forEach(item->{
            item.changePrice(curDeduct);
        });
        //检索是否有有优惠券;后返回
        List<SysProductShopPageRes> list = shopService.recognizeShopHaveCoupponPageRes(listItem);
        //无需查询count;
        page.setRecords(list);
        return page;
    }
}
